(in-package :context-indexing)

(defun foldl (function initial-value &rest sequences)
  (let ((fold initial-value))
    (apply #'map nil (op setf fold (apply function fold __)) sequences)
    fold))

(defun sum (function &rest sequences)
  (if sequences
      (apply #'foldl (op + _ (apply function __)) 0 sequences)
      (foldl #'+ 0 function)))
    
(defun map-into1 (function result-sequence &rest sequences)
  (apply #'map-into result-sequence function result-sequence sequences))
